package com.hiwhitley.easy.day04;

/**
 * Created by hiwhitley on 2016/6/6.
 */
public class JoinDemo {
    Worker worker01 = new Worker("Worker01");
    Worker worker02 = new Worker("Worker02");

    public static void main(String[] args) {
        joinDemo();
    }

    static void joinDemo() {
        Worker worker01 = new Worker("Worker01");
        Worker worker02 = new Worker("Worker02");
        worker01.start();
        System.out.println("启动线程1");
        try {
            worker01.join();
            System.out.println("启动线程2");
            worker02.start();
            worker02.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("主线程继续执行");
    }



    static class Worker extends Thread {
        public Worker(String target) {
            super(target);
        }

        @Override
        public void run() {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("work in" + getName() + " time:" + System.currentTimeMillis());
        }
    }
}
